package tests;

import java.util.Set;
import org.hibernate.FetchMode;
import org.hibernate.Session;
import org.hibernate.criterion.Expression;

import util.HibernateUtil;
import general.Formation;
import general.Personne;

@SuppressWarnings("deprecation")
public class Execution1{	
	public static void main(String[] args) {       	        
	        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
	        session.beginTransaction();	        
			Personne p1 = (Personne) session.createCriteria(Personne.class)
	            .setFetchMode("formations", FetchMode.LAZY)
	            .add(Expression.eq("id", new Long(1))).uniqueResult();
            System.out.println(p1);
           
            Set<Formation> lf = p1.getFormation();
            Formation f= lf.iterator().next(); 
            Set<Personne> lp = f.getAnciensMembres(); 

            for(Formation form: lf){System.out.println(form.getNom());}
            for(Personne pers: lp){System.out.println(pers.getNom());}
            session.getTransaction().commit();  
            
            
            
	}
}
